from sqlmodel import Session, create_engine, SQLModel
from typing import Annotated
from fastapi import Depends
import os

username = 'root'
password = '123456'
host = 'localhost'
port = '3306'
database = 'ping_pong_english'

db_url = os.getenv('DATABASE_URL') or f'mysql+pymysql://{username}:{password}@{host}:{port}/{database}'
engine = create_engine(db_url, echo=True)

def get_session():
    with Session(engine) as session:
        yield session

def create_db_and_tables():
    SQLModel.metadata.create_all(engine)


SessionDep = Annotated[Session, Depends(get_session)]